package com.example.authservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.authservice.pojo.vo.UserVo;
import com.example.authservice.service.UserService;
import com.example.baseserver.util.Reply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 鱼凫
 * @create 2023/3/3 16:08
 */
@CrossOrigin
@Controller
@Api(tags = "用户管理相关接口")
@RestController
@RequestMapping("api/user")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("根据id查询用户")
    @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "1", required = true)
    @GetMapping("get/{id}")
    public Reply selectOneById(@PathVariable("id") String id) {
        return userService.selectOneById(id);
    }

    @ApiOperation("更新用户信息")
    @PostMapping("modify")
    public Reply<UserVo> save(@RequestBody UserVo userVO) {
        return userService.update(userVO);
    }

    @ApiOperation("新增用户")
    @PostMapping("add")
    public Reply<UserVo> add(@RequestBody UserVo userVO) {
        return Reply.success(userService.addOneUser(userVO));
    }

    @ApiOperation("根据id删除用户")
    @GetMapping("delete/{id}")
    public  Reply deleteById(@PathVariable("id") String id){
        return userService.deleteById(id)>0 ? Reply.success():Reply.failed();
    }

    @PostMapping("page")
    @ApiOperation("获取用户列表(分页)")
    public Reply<Page<UserVo>> getPage(@RequestBody UserVo userVO){
        return Reply.success(userService.getPage(userVO));
    }
}


